# -$- coding:utf-8 -*-
class MainService(object):
    def __init__(self, conn):
        self.conn = conn

    def selectiochat(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from io_wechat_chat where status='' or status is null or status='0'"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectiochat_openid(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from io_wechat_chat where (openid is null or openid = 'null' or CHAR_LENGTH(openid)<10) and (status='' or status is null or status='0')"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectoialarm(self, tablename, where):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from " + tablename + " where 1=1" + where
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectoialarm_to110(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from oi_wechat_chat where status='' or status is null or status='0'"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectoicrjbills(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from oi_crj_bills"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectoicrjbills_tocrjglj(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from oi_crj_bills where is_collect <> '1'"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def selectoihzbills_tohz(self):
        try:
            cursor = self.conn.cursor()
            sql = "select count(*) from oi_hz_bills where is_collect = '0'"
            cursor.execute(sql)
            # print("oi_wechat_alarm:" + sql)
            rs = cursor.fetchall()
            return rs
        finally:
            cursor.close()

    def insterxx_1(self, id, uuid, msgtitle, msgcontent, except_send, recover_send, except_type):
        try:
            cursor = self.conn.cursor()
            sql = "insert into system_monitor_except (id,uuid,msgtitle,msgcontent,except_send,recover_send,except_type) values (%s,%s,%s,%s,%s,%s,%s)" % (
                id, uuid, msgtitle, msgcontent, except_send, recover_send, except_type)
            cursor.execute(sql)
            self.conn.commit()
            if cursor.rowcount != 1:
                return False
            else:
                return True
        finally:
            cursor.close()

    def selectxx_1(self):
        try:
            cursor = self.conn.cursor()
            sql = "select id from system_monitor_except order by id desc limit 1"
            # 互联网链接数据池
            cursor.execute(sql)
            returnstr = cursor.fetchall()
            return returnstr
        finally:
            cursor.close()
